﻿using System.Data.Common;
using System.Web.Configuration;
using System.Xml.Linq;
using System.Xml.Serialization;
using KS.DataWrapper.DataWrapper;
using KS.DataWrapper.DataWrapper.LINQ;
using Microsoft.AspNet.SignalR.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using WebApiHostTest.Models;
using System.Data.SqlClient;
using System.Linq.Expressions;
using System.IO;



namespace ClientTest
{
    //public class Customer
    //{
    //    public string CustomerID;
    //    public string ContactName;
    //    public bool Phone;
    //    public string City;
    //    public string Country;
    //}

    //public class Order
    //{
    //    public int OrderID;
    //    public string CustomerID;
    //    public DateTime OrderDate;
    //}

    //public class Northwind
    //{
    //    public Query<Customer> Customers;
    //    public Query<Order> Order;

    //    public Northwind(DbConnection connection)
    //    {
    //        QueryProvider provider = new WebApiQueryProvider(connection);
    //        this.Customers = new Query<Customer>(provider);
    //        this.Order = new Query<Order>(provider);
    //    }
    //}

    class Program
    {
        static void Main(string[] args)
        {
            //List<Order> lst = new List<Order>();
            //lst.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 1 });
            //lst.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 2 });
            //lst.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 3 });
            //lst.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 4 });
            //lst.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 5 });

            //List<Order> lst1 = new List<Order>();
            //lst1.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 1 });
            //lst1.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 2 });
            //lst1.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 3 });
            //lst1.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 4 });
            //lst1.Add(new Order() { OrderDate = System.DateTime.Now, OrderID = 5 });

            //var ex1 = lst.Where(w => w.OrderID > 3).AsQueryable().Expression;


            //IQueryable<Order> queryableData = lst1.AsQueryable<Order>();
            //var externals = new Dictionary<string, object>();
            //externals.Add("Products", queryableData);

            //string query = "Products.Where(w => w.OrderID > 3)";
            //var expression = System.Linq.Dynamic.DynamicExpression.Parse(typeof(IQueryable<Order>), query, new[] { externals });

            //var result = queryableData.Provider.CreateQuery<Order>(expression);

            
            ////var result = lst1.AsQueryable().Provider.Execute(expression);

          

            ////var ese = new ExpressionSerializer();
            ////var ex2 = ese.Deserialize(sss);

            ////var rez = lst1.AsQueryable().Provider.Execute(ex2);

            //Northwind nn = new Northwind(new SqlConnection());
            //var sss = nn.Customers.Where(w => w.City != "" && w.CustomerID.Contains("dd")).Where(w => !w.Phone).OrderBy(w => w.Country).GroupBy(g=>g.City).AsQueryable();
            ////var ttt = nn.Customers.Where(w => w.City != "" && w.CustomerID.Contains("dd")).ToString();

            //foreach (var item in sss)
            //{
            //    int a = 5;
            //}

            DataCacheObject<TestItemClass> test = new DataCacheObject<TestItemClass>(new Uri("http://localhost:1193/"),null);
            
            
            //test.Add(new TestItemClass() { ID = "1" });
            //test.Add(new TestItemClass() { ID = "2" });
            //test.Add(new TestItemClass() { ID = "3" });
            //test.Add(new TestItemClass() { ID = "4" });
            //test.Add(new TestItemClass() { ID = "5" });
            
            var dd = test.GroupBy(w => w.ID);

            var x = test.ServiceQuery.Where(w => w.ID != "1").Count();//.OrderBy(o => o.ID).GroupBy(o => o.ID).Take(10);

            //var d = x.Count();
            int c = 0;

            //foreach (var item in x)
            //{
            //    c++;
            //}
           
        }
    }
    
}

